/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package session;

import entity.Company;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author owtee
 */
@Stateless
public class CompanyFacade extends AbstractFacade<Company> {

    @PersistenceContext(unitName = "MSGPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public CompanyFacade() {
        super(Company.class);
    }

    public List<Company> findByName(String comName) {
        em.getEntityManagerFactory().getCache().evictAll();
        return em.createQuery("SELECT c FROM Company c WHERE c.comName LIKE :comName")
                .setParameter("comName", comName)
                .getResultList();
    }

    public List<Company> findByName(int start, int end, String comName) {
        em.getEntityManagerFactory().getCache().evictAll();
        return em.createQuery("SELECT c FROM Company c WHERE c.comName LIKE :comName")
                .setFirstResult(start)
                .setMaxResults(end)
                .setParameter("comName", comName)
                .getResultList();
    }

    public List<Company> findByActiveFlag(boolean activeFlag) {
        em.getEntityManagerFactory().getCache().evictAll();
        return em.createQuery("SELECT c FROM Company c WHERE c.activeFlag = :activeFlag")
                .setParameter("activeFlag", activeFlag)
                .getResultList();
    }
}
